package com.lhb.rabbit.controller;

import cn.hutool.json.JSONObject;
import com.lhb.rabbit.service.BasicPublisher;
import com.lhb.rabbit.service.JsonPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PubRest {

    @Autowired
    private BasicPublisher basicPublisher;

    @Autowired
    private JsonPublisher jsonPublisher;

    @GetMapping(path = {"","/","/publish"})
    public String publish(@RequestParam String name){
        JSONObject object = new JSONObject();
        object.put("basic", basicPublisher.publish(name));
        return object.toString();
    }


    @GetMapping(path = {"publish1"})
    public String publish1(@RequestParam String name){
        JSONObject object = new JSONObject();
        object.put("basic",basicPublisher.publish2mq2(name));
        return object.toJSONString(1);
    }

    @GetMapping(path = {"jsonPublish"})
    public String jsonPublish(@RequestParam String name){
        JSONObject object = new JSONObject();
        object.put("json",jsonPublisher.publish(name));
        return object.toString();
    }
}
